matplotlib figure layout
Tips
早く知っておきたかったmatplotlibの基礎知識、あるいは見た目の調整が捗るArtistの話 - Qiita
matplotlib: 論文用に図の体裁を整える - Qiita
「データ視覚化のデザイン `#1」をmatplotlibで実装する - Qiita
plt.close() だけではメモリが解放されない場合がある - Qiita
hr.icon
Figure
hr.icon
Zorder
図の重ね合わせの順番を変える
pylab_examples example code: zorder_demo.py
hr.icon
Room
Move the edge of an axes to make room for tick labels
Automatically make room for tick labels
hr.icon
Subplot
subplot
make subplot once at a time
subplots
make subplots all at once
subplot2grid()
Create an axis at specific location inside a regular grid.
subplot
code:python
plt.subplot(3,1,1)
plt.subplot(3,1,2)
plt.subplot(3,1,3)
subplots
prepare subplots
MetPy Mondays `#101 - Making Subplots the Smart Way! : Unidata Developer's Blog only 1 subplot
code:python
fig, ax = plt.subplots()
code:python
fig,axes=plt.subplots(3,3,figsize=8.27,11.69,subplot_kw={'projection': ccrs.PlateCarree()}) flatten axes
code:python
fig,axes=plt.subplots(3,3)
axes=axes.flatten()
flatten axes
code:python
for ax, df_key in zip(axes.flatten(), imputations):
....
remove last subplot
code:python
axlast.remove()
MetPy Mondays '#102: Using Dictionaries to Store Plotting Parameters : Unidata Developer's Blog MetPy Mondays `#124 - Aligning Labels in Matplotlib : Unidata Developer's Blog code:python
fig.align_labels()
Align y-labels
MetPy Mondays `#118 - Legends and Subplots : Unidata Developer's Blog
Examples on google collaboratory
GridSpec
Customizing Location of Subplot Using GridSpec
AxesGrid
Overview of AxesGrid toolkit
Demo Axes Grid
subplot_mosaic
hr.icon
Adjust Subplots
subplots_adjust
pylab_examples example code: subplots_adjust.py
Tight Layout
Tight Layout guide
Constrained Layout
The constrained layout and tight layout are two options available for layout management in Matplotlib. Constrained layout automatically adjusts the positions of subplots to fit their contents within the figure while avoiding overlaps. This is useful for creating complex plots with multiple subplots that would otherwise require manual adjustments.
On the other hand, tight layout adjusts the spacing between subplots to fit them within the figure without overlapping. However, this can sometimes result in elements being pushed too close, making them difficult to read.
In general, constrained layout is recommended when working with complex plots with multiple subplots, while tight layout may be more appropriate for simpler plots where readability is a priority. Ultimately, the choice between these two options depends on the specific needs of the visualization and the personal preferences of the user.
hr.icon
Fig size
MetPy Mondays '#128 - Sizing Figures for Publication : Unidata Developer's Blog Figures - American Meteorological Society
hr.icon
Inset Axes
Zoom region inset axes
MetPy Mondays `#120 - Inset Axes with RADAR data : Unidata Developer's Blog python - Cartopy coastlines hidden by inset_axes use of Axes.pie - Stack Overflow
python - embed small map (cartopy) on matplotlib figure - Stack Overflow
hr.icon
Examples
python - matplotlib write text in the margin - Stack Overflow
Matplotlib の多くのサブプロットでサブプロットのサイズまたは間隔を改善する方法 | Delft スタック
See also